package com.sh.shanhuo.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sh.shanhuo.R;
import com.sh.shanhuo.bean.ContentBean;

import java.util.List;

import androidx.cardview.widget.CardView;

public class ItemAdapter extends BaseQuickAdapter<ContentBean, BaseViewHolder> {

    private final Context context;

    public ItemAdapter(Context context, List<ContentBean> filterNames) {
        super(R.layout.item_view, filterNames);
        this.context = context;
    }

    @SuppressLint("UseCompatLoadingForDrawables")
    @Override
    protected void convert(BaseViewHolder helper, ContentBean item) {
        ImageView image = helper.getView(R.id.image);
        TextView message = helper.getView(R.id.message);
        TextView title = helper.getView(R.id.title);
        CardView imageView = helper.getView(R.id.imageView);
        int position = helper.getAdapterPosition();
        if (TextUtils.isEmpty(item.getContent())) {
            imageView.setVisibility(View.GONE);
            message.setVisibility(View.GONE);
            title.setVisibility(View.GONE);
        } else {
            imageView.setVisibility(View.VISIBLE);
            message.setVisibility(View.VISIBLE);
            title.setVisibility(View.VISIBLE);
            Glide.with(context).load(item.getUrl())
                    .placeholder(context.getDrawable(R.drawable.default_logo))
                    .error(context.getDrawable(R.drawable.default_logo))
                    .into(image);
            if (position == 0) {
                message.setText(item.getNum());
                Glide.with(context).load(context.getDrawable(R.drawable.icon_notice))
                        .into(image);
            } else {
                message.setVisibility(View.GONE);
            }
            title.setText(item.getContent());
        }

    }
}
